package shejimoshi.zhongjiezhemoshi;

import java.util.HashMap;
import java.util.Map;

// 具体中介者
public class ConcreteMediator implements Mediator {
    private Map<String, Colleague> colleagues = new HashMap<>();

    @Override
    public void register(String colleagueName, Colleague colleague) {
        colleagues.put(colleagueName, colleague);
    }

    @Override
    public void relay(String colleagueName, String message) {
        Colleague colleague = colleagues.get(colleagueName);
        if (colleague != null) {
            colleague.receive(message);
        }
    }
}
